/*NOTE: This file has been DISCARDED
 * @Author: Meroke
 * @Date: 2022-04-05 20:44:39
 * @LastEditors: Meroke
 * @LastEditTime: 2022-04-06 10:34:38
 * @Description: !! There is a serious memory allocation problem, so this file is discarded
 * @FilePath: \MDK-ARMe:\Program\Code\cpp\STM32\project\arm_test\Servo\Src\action_stack.c
 */
#include "action_stack.h"
Action_Stack st_head,st_tail;

uint8_t stack_init(Action_Stack st_head,Action_Stack st_tail)
{
    st_head = (struct Node *)malloc(sizeof(struct Node));
    st_tail = (struct Node *)malloc(sizeof(struct Node));
    st_head->prior = NULL;
    st_head->next = NULL;
    st_tail->prior = NULL;
    st_tail->next = NULL;
    return 1;
}
uint8_t push(Action_Stack st_head, uint8_t mode)
{
    Action_Node temp = (struct Node *)malloc(sizeof(struct Node));
    temp->mode = mode;
    temp->next=st_head->next;
    st_head->next->prior = temp;
    st_head->next = temp;
    temp->prior = st_head;
    return 1;
}
int32_t pop(Action_Stack st_head,Action_Stack st_tail)
{
    if(length(st_head)<=0)
        return -1;
    uint8_t mode = 0;
    Action_Node temp = st_tail->prior;
    mode = temp->mode;
    temp->prior->next = temp->next;
    temp->next->prior=temp->prior;
    free(temp);
    return mode;       
}
uint8_t length(Action_Stack st_head)
{
    uint8_t len = 0;
    Action_Node head = st_head->next;
    while(head != NULL)
    {
        len ++;
        head = head->next;
    }
    return len -1;   
}

